package com.youi.web;

import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.youi.exception.BusinessException;
import com.youi.manage.HttpRequestManage;
import com.youi.common.DelStatus;
import com.youi.service.MerchantsettlementService;
import com.youi.entity.Merchantsettlement;
import com.youi.common.Common;
import com.youi.util.CommonInfoUtil;
import com.youi.util.DateUtil;
import com.youi.util.JsonUtil;
import com.youi.util.ObjectUtil;
import com.youi.util.Page;

/**
* 商家结算信息控制层
* @author Administrator
*/
@Controller
public class MerchantsettlementController  extends HttpRequestManage{

		@Autowired
		private MerchantsettlementService merchantsettlementService;

		/**
		 * I-79
		 *添加或编辑商家结算信息
		*/
		@ResponseBody
		@RequestMapping("sysUserGetInfo/addOrEditMerchantsettlement")
		public String addOrEditMerchantsettlement(ModelMap modelMap,HttpServletRequest request)throws BusinessException,ParseException{
			Long id=getLong("id",request);
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put("merchantId", id);
			Merchantsettlement merchantsettlement=merchantsettlementService.getByParam(prams);
			if (merchantsettlement==null) {
				merchantsettlement=new Merchantsettlement();
				merchantsettlement.setDelStatus(DelStatus.NODEL);
				merchantsettlement.setGmtCreated(new Date());
				merchantsettlement.setMerchantId(id);
			}
			String itinNo=optString("itinNo",request);
			if (itinNo!=null){
				merchantsettlement.setItinNo(itinNo);
			}
			Integer isLimitSettle=optInteger("isLimitSettle",request);
			if (isLimitSettle!=null){
				merchantsettlement.setIsLimitSettle(isLimitSettle);
			}
			String bankcardNo=optString("bankcardNo",request);
			if (bankcardNo!=null){
				merchantsettlement.setBankcardNo(bankcardNo);
			}
			String name=optString("name",request);
			if (name!=null){
				merchantsettlement.setName(name);
			}
			String bank=optString("bank",request);
			if (bank!=null){
				merchantsettlement.setBank(bank);
			}
			String bankCode=optString("bankCode", request);
			if (bankCode!=null) {
				merchantsettlement.setBankCode(bankCode);
			}
			String branchCode=optString("branchCode", request);
			if (branchCode!=null) {
				merchantsettlement.setBranchCode(branchCode);
			}
			String province=optString("province",request);
			if (province!=null){
				merchantsettlement.setProvince(province);
			}
			String city=optString("city",request);
			if (city!=null){
				merchantsettlement.setCity(city);
			}
			String district=optString("district",request);
			if (district!=null){
				merchantsettlement.setDistrict(district);
			}
			String bankBranch=optString("bankBranch",request);
			if (bankBranch!=null){
				merchantsettlement.setBankBranch(bankBranch);
			}
			Date gmtSettle=optDate("gmtSettle", request, "yyyy-MM-dd HH:mm:ss");
			if (gmtSettle!=null) {
				merchantsettlement.setGmtSettle(gmtSettle);
			}
			merchantsettlement.setGmtModify(new Date());
			merchantsettlementService.saveOrUpdate(merchantsettlement);
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成");
		}


		/**
		 * I-80
		 * 查询商家结算信息
		*/
		@ResponseBody
		@RequestMapping("sysUserGetInfo/getMerchantsettlementById")
		public String getMerchantsettlementById(ModelMap modelMap,HttpServletRequest request) throws BusinessException{
			Long id=getLong("id",request);
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put("merchantId", id);
			Merchantsettlement merchantsettlement=merchantsettlementService.getByParam(prams);
			if (merchantsettlement==null) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
			}
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成",merchantsettlement);//jsonObject	json对象
		}

		
}
